package com.zxlspace.java8;

import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @ClassName TestStreamList
 * @Description TODO
 * @Author zhangxiaolin@pinpianyi.com
 * @Date 2019/4/3 18:13
 * @Version 1.0
 **/
public class TestStreamList {
    public static void main(String[] args) {
        List<Apple> appleList = new ArrayList<Apple>();
        Apple apple1 = new Apple(1, Color.GREEN.getDesc(), 1500);
        Apple apple2 = new Apple(2, Color.RED.getDesc(), 1000);
        Apple apple3 = new Apple(3, Color.YELLOW.getDesc(), 2500);
        Apple apple4 = new Apple(4, Color.GREEN.getDesc(), 1800);
        Apple apple5 = new Apple(5, Color.YELLOW.getDesc(), 500);
        Apple apple6 = new Apple(6, Color.RED.getDesc(), 150);
        appleList.add(apple1);
        appleList.add(apple2);
        appleList.add(apple3);
        appleList.add(apple4);
        appleList.add(apple5);
        appleList.add(apple6);
        //stream() 顺序处理
        List<Apple> newAppleList = appleList.stream().filter((Apple a) -> a.getColor().equals(Color.RED.getDesc())).collect(Collectors.toList());
        System.out.println(JSONObject.toJSON(newAppleList));

        //parallelStream 并行处理
        List<Apple> heavyApples =
                appleList.parallelStream().filter((Apple a) -> a.getWeight() > 1000).collect(Collectors.toList());
        System.out.println(JSONObject.toJSON(heavyApples));
    }
}

class Thread1 implements Runnable {

    @Override
    public void run() {

    }
}
